<?php
namespace AuctionCore\CarOwner;


/**
*车主功能单元测试
*@author爱民
*/
class OwnerTest extends \PHPUnit_Framework_TestCase
{

	private $owner_id = null; 
	public  static $owner_info = array(  
						'uid'=>0,
						'service_id'=>'33',
						//'checker_id'=>'22',
						'seller_name'=>'test',
						'phone'=>'13552528384',
						'reg_time'=>888888,
						'car_model'=>'雪铁龙',
						'business_status'=>2,
						'mileage'=>'15.5',
						'first_reg_time'=>888888,
						'status'=>2,
						'comefrom'=>1,
						'first_reg_city'=>10,
						//'service_method'=>1,
						//'next_trace_time'=>888888,
						'posttime'=>888888,
						'certificate_type'=>1,
						'certificate_number'=>'008829289999',
						'province'=>1,
						'city'=>2,
						'area'=>3,
						'address'=>'小康村55号',
						//'reserve_time'=>888888,
						//'reserve_remark'=>'',
						//'reserve_area'=>1,
						//'reserve_city'=>2,
						//'reserve_provinc'=>3,
						//'reserve_address'=>'回漳村',
						//'assgin_remark'=>'',
						//'checker_name'=>'张小飞',
						'audit_remark'=>'',
						'check_date'=>888888,
					);

	public function testCreate(){
		//创建
		$info = self::$owner_info;
		$id = Owner::create(self::$owner_info);
		$this->assertFalse(!$id);
		$this->owner_id = $id;

		//更新
		$owner = new \AuctionCore\CarOwner\Owner($id);
		$info = array("car_model"=>'雪铁龙8888');
		$ok = $owner->update($info);
		$this->assertEquals(1,$ok);		
	}

	public function testOwnerCreateException(){		
		try{
			$info = self::$owner_info;
			$info['seller_name'] = '';
			$id = Owner::create($info);
		}catch(\Exception $e){
		    //车主姓名无效			
			$this->assertTrue(400001==$e->getCode());
		}

		try{
			$info = self::$owner_info;
			$info['phone'] = '';
			$id = Owner::create($info);
		}catch(\Exception $e){
			//车主电话无效
			$this->assertTrue(400002==$e->getCode());
		}
	}


	public function testEnableFrontUser(){
		//创建
		$info = self::$owner_info;
		$id = Owner::create(self::$owner_info);		
		//开通网站登录
		//[用户名，密码,昵称,密保手机号,短信手机号]
		$owner = new Owner($id);
		$user_info = array();
		$user_info['user_name'] = 'test_enable_frontuser';
		$user_info['passwd'] = 'cccccc';
		$user_info['nick_name'] = 'test_enable_frontuser';
		$user_info['sms_mobile'] = '13666666666';
		$user_info['pwd_mobile'] = '13777777777';
		
		$user_id = $owner->enable_front_user($user_info);
		$this->assertTrue(intval($user_id)>0);
		//车主详细
		$deatil = $owner->detail();	

		//删除车主信息
		//Owner::remove($id);
		//删除用户信息
		//\AuctionCore\Account\FrontUser::remove('test_enable_frontuser');

	}

	public function testBookingSucess(){
		$now = date("Y-m-d H:i:s",time());
		$now2 = date("Y-m-d H:i:s",time()+86000);
		
		$this->testCreate();		
		$owner = new Owner($this->owner_id);

		//车主预约跟踪
		$booking_trace_info = array(     
                'waiter_id'=>1     //客服id  
                ,'name' => 'unit_test'    //客服姓名
                ,'remark' => '预约跟踪备注' //跟踪备注
                ,'next_trace_time' => $now //下次预约时间 
        );
		$ok = $owner->booking_trace($booking_trace_info);
		$this->assertTrue(intval($ok)>0);
		
		//车主预约成功
		$booking_sucess_info = array(
	        'reserve_time'=>$now2  //预约时间 
	        ,'service_method'=>'1' 
	        ,'reserve_provinc'=>'1'//省 
	        ,'reserve_city'=>'1'  //城市编号
	        ,'reserve_area'=>'1'  //地区编号
	        ,'reserve_address'=>'北里58号' //详址
	        ,'reserve_remark' =>'成功预约备注'
	        ,'service_id'=>1     //客服id  
            ,'service_name' => 'unit_test'    //客服姓名
	    );
		$ok = $owner->booking_sucess($booking_sucess_info);
		$this->assertTrue(intval($ok)>0);

		//车主预约日志
		$log_list = $owner->booking_log();
		$this->assertEquals(2,count($log_list));
		
		//删除车主信息
		Owner::remove($this->owner_id);
		$re_treace = M('reserve_trace');
        $where = "owner_id='{$this->owner_id}'";
        $re_treace->where($where)->delete();
		
	}

	public function testBookingFaild(){
		$now = date("Y-m-d H:i:s",time());
		$now2 = date("Y-m-d H:i:s",time()+86000);
		
		$this->testCreate();		
		$owner = new Owner($this->owner_id);
		

		//车主预约失败
		$booking_faild_info = array(     
                'waiter_id'=>1     //客服id  
                ,'name' => 'unit_test'    //客服姓名
                ,'remark' => '预约失败' //跟踪备注
        );
		$ok = $owner->booking_faild($booking_faild_info);
		$this->assertTrue(intval($ok)>0);

		//分配评估师
		$ok = $owner->assgin_checker(1, 'unit_test', '分配评估师');
		$deatil = $owner->detail();		
		$this->assertEquals($deatil['checker_id'],1);

		//删除车主信息
		Owner::remove($this->owner_id);
		$re_treace = M('reserve_trace');
        $where = "owner_id='{$this->owner_id}'";
        $re_treace->where($where)->delete();
				
	}

	public function testAA(){
		echo gettype(888);
	}


}

?>